﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;
namespace NotebookS2
{
    public partial class FND_JOURNALVOUCHER : RibbonForm
    {
        public FND_JOURNALVOUCHER()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public string SelectedDocumentNumber { get; set; }

        private void FND_JOURNALVOUCHER_Load(object sender, EventArgs e)
        {
            cboSearch.SelectedIndex = 0;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            JVManager oManager = new JVManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable dt = new DataTable();
            //Document Number
            //Customer
            //Remarks
            switch (cboSearch.SelectedIndex)
            {
                case 0:
                    dt = oManager.BrowseJVByDocumentNumber(txtSearch.Text);
                    break;
                case 1:
                    dt = oManager.BrowseJVByCardName(txtSearch.Text);
                    break;
                case 2:
                    dt = oManager.BrowseJVByRemarks(txtSearch.Text);
                    break;
            }

            gridControl1.DataSource = dt;
            gridControl1.Refresh();

            oManager.Close();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            this.SelectedDocumentNumber = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["DocNum"]).ToString();
            this.Close();
        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtSearch_ButtonClick(null, null);

                gridView1.Focus();
            }
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(null, null);
        }
    }
}

